%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% KING2BISHOPKING
%
% AUTHOR: 
%
% DATE: ???
%
% SOURCES:
%   ChessOntolog.pl
%   Gatine M (ed) (2003) Larousse del ajedrez. Spes Editorial, Barcelona
%   
%
% The command to start the game is "play."
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ataqueMateBishop(no).

%%%%%%%
%
% king2bishopKing/1 
%
% Identifica que la posicion sea del tipo KingQueenKing
%
%%%%%%%

king2bishopKing(Position) :-
        findall(Piece,isInSquare(Position, Piece, _File, _Rank),L),
        king(King1), king(King2), bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasColour(King1, Colour), hasColour(Bishop1, Colour), hasColour(Bishop2, Colour),
        hasOpponentPiece(Bishop1, King2),
        member(King1,L),
        eliminaLista(King1,L,L2),
        member(King2,L2),
        eliminaLista(King2,L2,L3),
        member(Bishop1,L3),
        eliminaLista(Bishop1,L3,L4),
        member(Bishop2,L4),
        eliminaLista(Bishop2,L4,[]).
        

       
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% evaluatePosition/2
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                        

%Rey Ahogado

evaluateK2BKPosition(Position, -40000, explanationNeg) :-
        computer(Player),
        bishop(ComputerBishop),
        king(OpponentKing),
        hasOpponentPiece(ComputerBishop, OpponentKing),
        hasPiece(Player, ComputerBishop),
        kingAhogado(Position, OpponentKing), !.

% The bishop should not be attacked when the black is the player who has the move.

evaluateK2BKPosition(Position, -20000, attackedBishop) :-
        computer(Player),
        bishop(ComputerBishop),
        king(OpponentKing),
        hasOpponentPiece(ComputerBishop, OpponentKing),
        hasPiece(Player, ComputerBishop),
        isInSquare(Position, ComputerBishop, I, J),
        legalMove(Position, OpponentKing, I, J), !.
 
 
%FIGURA 2 
evaluateK2BKPosition(Position,40000,forcingBackward):-
        ataqueMateBishop(no),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        isInSquare(Position, ComputerKing, CKC, CKF),
        hasNumberOfFile(B1C,NB1C),
        hasNumberOfFile(OKC,NOKC),
        
        (NB1C =:= NOKC),
        (abs(B1F - OKF) =:= 2),
        cautionBishopSquare(OKC,OKF,B1C,B1F,CB1C,CB1F),
        legalMove(Position, Bishop2, CB1C, CB1F),
        
        %MISMA FILA LOS 2 BISHOPS
        (B1F =:= B2F),

        cautionBishopSquare(OKC,OKF,B2C,B2F,CB2C,CB2F),
        manhattanDistance(CB2C,CB2F,CKC,CKF,1) , !.
 
 
%FIGURA 4 
evaluateK2BKPosition(Position,25000,limitingZoneMoves):-
        ataqueMateBishop(no),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        isInSquare(Position, ComputerKing, CKC, CKF),
        hasNumberOfFile(B1C,NB1C),
        hasNumberOfFile(B2C,NB2C),
        hasNumberOfFile(OKC,NOKC),
        hasNumberOfFile(CKC,NCKC),
        
       
        (abs(B1F - OKF) =:= 2),
        (abs(B2F - OKF) =:= 3),
        NB1C =:= NB2C,
        CKF =:= B1F,
        
        (
        ( (NB1C =:= NOKC) , (abs(NCKC - NOKC) =:= 1) )
        ;
        ( (abs(NB1C - NOKC) =:= 1) , (abs(NB1C - NCKC) =:= 1) , (abs(NCKC - NOKC) =:= 2) )
        ) , !.
        

%FIGURA 1
evaluateK2BKPosition(Position,V,Explanation):-
        ataqueMateBishop(no),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        isInSquare(Position, ComputerKing, CKC, CKF),
        hasNumberOfFile(B1C,NB1C),
        hasNumberOfFile(OKC,NOKC),    
        
        (NB1C =:= NOKC),
        (abs(B1F - OKF) =:= 2),
        cautionBishopSquare(OKC,OKF,B1C,B1F,CB1C,CB1F),
        legalMove(Position, Bishop2, CB1C, CB1F),
        
        %MISMA FILA LOS 2 BISHOPS
        (B1F =:= B2F),
        
        DifRankCKB is ((abs(B1F - CKF)) * 10),
        
        manhattanDistance(CKC,CKF,B1C,B1F,MDB1CK),
        manhattanDistance(CKC,CKF,B2C,B2F,MDB2CK),
        
        %UTIL PARA SABER SI SE REALIZA MOVIMIENTO DE ESPERA
        ((B1F =:= CKF ,Explanation = sameRankKing);(Explanation = joiningBishops)),
        
        ( (B1F =:= CKF , (MDB1CK + MDB2CK) < 6) ; (\+(B1F =:= CKF)) ),
        
        V is 30000 + (100 - DifRankCKB) + (20 - MDB1CK), 
        
        ( 
        ( B1F =:= CKF, (OKF =:= 1 ; OKF =:= 8),  (MDB1CK + MDB2CK) =:= 3 ,
        retractall(ataqueMateBishop(no)), assert(ataqueMateBishop(yes)) ) 
        ; 
        (\+ fail) 
        ) , !.        
        
           
%FIGURA 3
evaluateK2BKPosition(Position,V,bishopCoveringBishop):-
        ataqueMateBishop(no),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        hasNumberOfFile(B1C,NB1C),
        hasNumberOfFile(OKC,NOKC),   
        
        (NB1C =:= NOKC),
        (abs(B1F - OKF) =:= 2),
        cautionBishopSquare(OKC,OKF,B1C,B1F,CB1C,CB1F),
        legalMove(Position, Bishop2, CB1C, CB1F),
        
        kingDistance(B1C,B1F,B2C,B2F,KDBishops),
        
        V is 20000 + (50 - KDBishops), !.
        
 
%FIGURA 2 PERO DIFRANK = 3
%CASO ESPECIFICO REY CUBRE POSIBLE ESCAPE LATERAL MIENTRAS BAJAN BISHOPS
evaluateK2BKPosition(Position,15000,preventingLateralEscapeWithKing):-
        ataqueMateBishop(no),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        isInSquare(Position, ComputerKing, CKC, CKF),
        hasNumberOfFile(B1C,NB1C),
        hasNumberOfFile(B2C,NB2C),
        hasNumberOfFile(OKC,NOKC),
        hasNumberOfFile(CKC,NCKC),
        
        (NB1C =:= NOKC),
        (abs(B1F - OKF) =:= 3),
        cautionBishopSquare(OKC,OKF,B1C,B1F,CB1C,CB1F),
        legalMove(Position, Bishop2, CB1C, CB1F),
        
        abs(NB1C - NB2C) =:= 1,
        abs(NB1C - NCKC) =:= 1,
        abs(NB2C - NCKC) =:= 2,
        
        
        %MISMA FILA LOS 2 BISHOPS
        (B1F =:= B2F),

        cautionBishopSquare(OKC,OKF,B1C,B1F,CB1C,CB1F),
        manhattanDistance(CB1C,CB1F,CKC,CKF,1) , !.
   
    
%FIGURA 1 PERO A DISTANCIA 3 ENTRE FILAS
evaluateK2BKPosition(Position,V,Explanation):-
        ataqueMateBishop(no),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        isInSquare(Position, ComputerKing, CKC, CKF),
        hasNumberOfFile(B1C,NB1C),
        hasNumberOfFile(OKC,NOKC),  
        
        
        (abs(B1F - OKF) =:= 3),
        cautionBishopSquare(OKC,OKF,B1C,B1F,CB1C,CB1F),
        legalMove(Position, Bishop2, CB1C, CB1F),
        
        %MISMA FILA LOS 2 BISHOPS
        (B1F =:= B2F),
 
        
        (NOKC =:= NB1C),
        %DifColOKB1 is abs(NOKC - NB1C),
        %DifColOKB2 is abs(NOKC - NB2C),
        %(DifColOKB1 + DifColOKB2) =< 3,
        
        
        DifRankCKB is ((abs(B1F - CKF)) * 10),
        
        %UTIL PARA SABER SI SE REALIZA MOVIMIENTO DE ESPERA
        ((B1F =:= CKF ,Explanation = sameRankKing);(Explanation = joiningBishops)),
        
        manhattanDistance(CKC,CKF,B1C,B1F,MDB1CK),
        
        V is 10000 + (100 - DifRankCKB) + (20 - MDB1CK), !.  


%UN ALFIL ENCIMA DEL OTRO
%CASO ESPECIFICO EN EL QUE EL REY CUBRE LA VIA DE ESCAPE CON DIFRANK = 2
evaluateK2BKPosition(Position,V,limitingZoneMovesWithBishop):-
        ataqueMateBishop(no),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        isInSquare(Position, ComputerKing, CKC, CKF),
        hasNumberOfFile(B1C,NB1C),
        hasNumberOfFile(B2C,NB2C),
        hasNumberOfFile(OKC,NOKC),
        hasNumberOfFile(CKC,NCKC),    
        
        (NB1C =:= NB2C),
        (abs(B1F - B2F) =:= 1),
        
        DifRankB1 is abs(OKF - B1F),
        DifRankB2 is abs(OKF - B2F),
        
        DifRankB2 < DifRankB1,
        
        DifRankB2 = 2,
        
        abs(NOKC - NB1C) =:= 2,
        
        CKF =:= B2F,
        NCKC =:= NOKC,
        
        V is (2000 - (DifRankB2*100)) + 3, !.  
        
 
%UN ALFIL ENCIMA DEL OTRO
%PARA PERFECCIONARLO FALTA EVITAR QUE SE PONGA EL REY EN LA DIAGONAL ESTORBANDO
evaluateK2BKPosition(Position,V,limitingZoneMovesWithBishop):-
        ataqueMateBishop(no),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        isInSquare(Position, ComputerKing, CKC, CKF),
        hasNumberOfFile(B1C,NB1C),
        hasNumberOfFile(B2C,NB2C),
        hasNumberOfFile(OKC,NOKC),
            
        
        (NB1C =:= NB2C),
        (abs(B1F - B2F) =:= 1),
        
        DifRankB1 is abs(OKF - B1F),
        DifRankB2 is abs(OKF - B2F),
        
        DifRankB2 < DifRankB1,
        
        cautionBishopSquare(OKC,OKF,B2C,B2F,CB2C,CB2F),
        kingDistance(OKC,OKF,CB2C,CB2F,KD),
        KD > 1, 
        
        DifRankB2 >= 3,
        
        Aux = DifRankB2 - 1,
        
        abs(NOKC - NB1C) =< Aux,
        
        \+ derecha(B2C,B2F,CKC,CKF),
        \+ izquierda(B2C,B2F,CKC,CKF),
        
        \+ (CB2F =:= CKF, manhattanDistance(CKC,CKF,CB2C,CB2F,MD), MD =< 2),
        
        V is (1000 - (DifRankB2*100)) + 3, !.
      
    
    
%UN ALFIL AL LADO DEL OTRO
evaluateK2BKPosition(Position,V,joiningBishopsLimiting):-
        ataqueMateBishop(no),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        
        (B1F =:= B2F),
        manhattanDistance(B1C,B1F,B2C,B2F,1),

        DifRank is abs(OKF - B2F),
        
        DifRank >= 3,
           
        V is (1000 - (DifRank*100)) + 2, !.
      
      
%UN ALFIL SOLO
evaluateK2BKPosition(Position,V,Explanation):-
        ataqueMateBishop(no),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        hasNumberOfFile(B1C,NB1C),
        hasNumberOfFile(OKC,NOKC),
        
        abs(NOKC - NB1C) =< 1, 
        abs(OKF - B1F) >= 3,        
               
        ((cautionBishopSquare(OKC,OKF,B1C,B1F,CB1C,CB1F),
        legalMove(Position, Bishop2, CB1C, CB1F), 
        Plus is 1, Explanation = bishopCoveringBishop)
        ;
        (Plus is 0, Explanation = bishopAttackingInSolitaire)),
       
        DifRank is abs(OKF - B1F),
       
        ((DifRank >= 3, Sub is 0);(Sub is 1000)),
       
        V is (1000 - (DifRank*100)) + Plus - Sub, !.
      
 

%MATE CUANDO YA ESTA EN FILA 1 u 8
evaluateK2BKPosition(Position,V,finalMate):-
        ataqueMateBishop(yes),
        computer(Player),
        king(OpponentKing),
        king(ComputerKing),
        bishop(Bishop1), bishop(Bishop2), \+ (Bishop1 = Bishop2),
        hasPiece(Player,Bishop1), hasPiece(Player,Bishop2), hasPiece(Player,ComputerKing),
        hasOpponentPiece(Bishop1,OpponentKing),
        isInSquare(Position, Bishop1, B1C, B1F),
        isInSquare(Position, Bishop2, B2C, B2F),
        isInSquare(Position, OpponentKing, OKC, OKF),
        isInSquare(Position, ComputerKing, CKC, CKF),
        hasNumberOfFile(OKC,NOKC),
        
        
        %IGUALANDO LA FILA DEL REY A LA ACTUAL EVITAMOS QUE SE ALEJE
        ((OKF =:= 1, AuxF is 2, CKF =:= 3) ; (OKF =:= 8, AuxF is 7, CKF =:= 6)),

        %LAS PIEZAS DEBEN ATACAR TODAS LAS VIAS DE ESCAPE A TRAVES DE LA FILA SUPERIOR O INFERIOR DEL OPPKING 
        (legalMove(Position, Bishop1, OKC, AuxF) ;
        legalMove(Position, Bishop2, OKC, AuxF) ;
        attacksSquare(Position, ComputerKing, OKC, AuxF)) ,
        
        %CASO ESQUINA IZQUIERDA
        ((NOKC =:= 1);
        (
        NE2C is NOKC - 1 , hasNumberOfFile(E2C,NE2C),
        (legalMove(Position, Bishop1, E2C, AuxF) ;
        legalMove(Position, Bishop2, E2C, AuxF) ;
        attacksSquare(Position, ComputerKing, E2C, AuxF))
        )),
        
        %CASO ESQUINA DERECHA
        ((NOKC =:= 8);
        (
        NE3C is NOKC + 1 , hasNumberOfFile(E3C,NE3C),
        (legalMove(Position, Bishop1, E3C, AuxF) ;
        legalMove(Position, Bishop2, E3C, AuxF) ;
        attacksSquare(Position, ComputerKing, E3C, AuxF))
        )), 
        
        kingDistance(B1C,B1F,B2C,B2F,KDBishops),
        
        
        %QUITAMOS VALOR SI LOS BISHOPS SE ENCUENTRAN EN LA MISMA FILA QUE OPPKING
        ((OKF =:= B1F, Sub1 is 50);(Sub1 is 0)),
        ((OKF =:= B2F, Sub2 is 50);(Sub2 is 0)),        
        
        manhattanDistance(CKC,CKF,OKC,CKF,MDBestKing),
        
        (
        ((isInSquare(Position, Bishop1, OKC, CKF) ; isInSquare(Position, Bishop2, OKC, CKF)),
        BotherBishop is 50)
        ;
        (BotherBishop is 0)
        ),

        lateralExitKing(OKC,OKF,OKEC,OKEF),
        (
        ((legalMove(Position, Bishop1, OKEC, OKEF) ; legalMove(Position, Bishop2, OKEC, OKEF)), PlusNoExit is 30)
        ;
        (PlusNoExit is 0)
        ),
        
        (
        ((legalMove(Position, Bishop1, OKC, OKF) ; legalMove(Position, Bishop2, OKC, OKF)), PlusJaque is 20)
        ;
        (PlusJaque is 0)
        ),
        
        lateralSecondExitKing(OKC,OKF,OKE2C,OKE2F),
        (
        ((legalMove(Position, Bishop1, OKE2C, OKE2F) ; legalMove(Position, Bishop2, OKE2C, OKE2F)), PlusNoExit2 is 10)
        ;
        (PlusNoExit2 is 0)
        ),
        
        BestKing is (800 - (MDBestKing*80)),
        
        V is 100 - KDBishops - Sub1 - Sub2 + BestKing - BotherBishop + PlusNoExit + PlusNoExit2 + PlusJaque, !.
        
      
evaluateK2BKPosition(_Position,0, indiferent):-!.

%moveK2BKExplanation(Explanation, _Piece, Explanation).

moveK2BKExplanation(_Exp, _ComputerBishop, savingBishop):-
	evaluateKRKPosition(0, _Value, attackedBishop), !.

moveK2BKExplanation(forcingBackward, _Piece, forcingBackward):- !.
        
moveK2BKExplanation(limitingZoneMoves, ComputerKing, coveringAttack2Bishop):-
        computer(Player),
        king(ComputerKing),
        hasPiece(Player, ComputerKing), !.
        
moveK2BKExplanation(limitingZoneMoves, ComputerBishop, limitingZoneMovesWithBishop):-
        computer(Player),
        bishop(ComputerBishop),
        hasPiece(Player, ComputerBishop), !.
        
moveK2BKExplanation(joiningBishops, ComputerBishop, joiningBishopsLimiting):-
        computer(Player),
        bishop(ComputerBishop),
        hasPiece(Player, ComputerBishop), !.  

moveK2BKExplanation(sameRankKing, ComputerBishop, joiningBishopsLimiting):-
        computer(Player),
        bishop(ComputerBishop),
        hasPiece(Player, ComputerBishop), !. 
  
moveK2BKExplanation(joiningBishops, ComputerKing, approachingKing):-
        computer(Player),
        king(ComputerKing),
        hasPiece(Player, ComputerKing), !.      

moveK2BKExplanation(sameRankKing, ComputerKing, approachingKing):-
        computer(Player),
        king(ComputerKing),
        hasPiece(Player, ComputerKing),
	evaluateK2BKPosition(0, _V, joiningBishops), !.

moveK2BKExplanation(sameRankKing, ComputerKing, waitingMove):-
        computer(Player),
        king(ComputerKing),
        hasPiece(Player, ComputerKing),
	evaluateK2BKPosition(0, _V, sameRankKing), !.        
       
moveK2BKExplanation(bishopCoveringBishop, _ComputerBishop, bishop1CoverBishop2):-
        \+ (
        evaluateK2BKPosition(0, _V1, joiningBishops);
        evaluateK2BKPosition(0, _V2, sameRankKing);
        evaluateK2BKPosition(0, _V3, joiningBishopsLimiting)
        ), !.
        
moveK2BKExplanation(bishopCoveringBishop, _ComputerBishop, limitingZoneMovesWithBishop):-
        (
        evaluateK2BKPosition(0, _V1, joiningBishops);
        evaluateK2BKPosition(0, _V2, sameRankKing);
        evaluateK2BKPosition(0, _V3, joiningBishopsLimiting)
        ), !.
        
moveK2BKExplanation(bishopAttackingInSolitaire, _ComputerBishop, bishopAttackingInSolitaire):- !.
        
moveK2BKExplanation(joiningBishopsLimiting, _ComputerBishop, joiningBishopsLimiting):- !.

moveK2BKExplanation(preventingLateralEscapeWithKing, _Piece, preventingLateralEscapeWithKing):- !.        

moveK2BKExplanation(limitingZoneMovesWithBishop, _ComputerBishop, limitingZoneMovesWithBishop):- !.    
        
moveK2BKExplanation(finalMate, ComputerKing, limitingZoneMovesWithKing):- 
        computer(Player),
        king(ComputerKing),
        hasPiece(Player, ComputerKing), !.  
        
moveK2BKExplanation(finalMate, ComputerBishop, limitingVerticalMovesWithBishop):- 
        computer(Player),
        bishop(ComputerBishop),
        hasPiece(Player, ComputerBishop), 
        \+ evaluateK2BKPosition(0, _V, finalMate), !.
       
moveK2BKExplanation(finalMate, ComputerBishop, bishopGoingDontBotherKing):- 
        computer(Player),
        bishop(ComputerBishop),
        hasPiece(Player, ComputerBishop),
        king(OpponentKing),
        hasOpponentPiece(ComputerBishop,OpponentKing),
        isInSquare(0,OpponentKing,OKC,OKF),
        isInSquare(0,ComputerBishop,OKC,BF),
        abs(OKF - BF) =:= 2,
        !. 
        
moveK2BKExplanation(finalMate, ComputerBishop, limitingHorizontalMovesWithBishop):- 
        computer(Player),
        bishop(ComputerBishop),
        hasPiece(Player, ComputerBishop),
        \+ (king(OpponentKing),
        hasOpponentPiece(ComputerBishop,OpponentKing),
        isInSquare(0,OpponentKing,OKC,OKF),
        isInSquare(0,ComputerBishop,OKC,BF),
        abs(OKF - BF) =:= 2), !.